package com.sky.controller.admin;

import com.sky.dto.IdDTO;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单管理")
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * Admin订单查询
     * @param ordersPageQueryDTO
     * @return
     */
    @ApiOperation("Admin订单查询")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        return Result.success(orderService.pageOrderQuery(ordersPageQueryDTO,"admin"));
    }
    /**
     * Admin订单详情
     * @param id
     * @return
     */
    @ApiOperation("Admin订单详情")
    @GetMapping("/details/{id}")
    public Result<Orders> detail(@PathVariable Long id) {
        return Result.success(orderService.getAllOrderDetail(id,"admin"));
    }
    /**
     * Admin个个状态订单数量统计!
     * @return
     */
    @ApiOperation("Admin个个状态订单数量统计!")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> orderStatistics() {
        return Result.success(orderService.orderStatistics());
    }
    /**
     * 拒单操作
     * @param ordersRejectionDTO
     * @return
     */
    @ApiOperation("拒单操作")
    @PutMapping("/rejection")
    public Result<String> rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }
    /**
     * 管理员取消订单
     * @param ordersCancelDTO
     * @return
     */
    @ApiOperation("管理员取消订单")
    @PutMapping("/cancel")
    public Result<String> cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }
    /**
     * 完成订单
     * @param id
     * @return
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result<String> complete(@PathVariable Long id) {
        orderService.complete(id);
        return Result.success();
    }
    /**
     * 拍送订单
     * @param id
     * @return
     */
    @ApiOperation("拍送订单")
    @PutMapping("/delivery/{id}")
    public Result<String> delivery(@PathVariable Long id) {
        orderService.delivery(id);
        return Result.success();
    }
    /**
     * 接单
     * @param idDTO
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result<String> confirm(@RequestBody IdDTO idDTO){
        log.info("接单:{}",idDTO.getId());
        orderService.confirm(idDTO.getId());
        return Result.success();
    }
}
